package com.example.bakend.controller;

import com.example.bakend.pojo.Category;
import com.example.bakend.pojo.Result;
import com.example.bakend.service.CategoryService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    @PostMapping
    public Result insertCategory(@RequestBody Category category){
        return Result.success(categoryService.insertCategory(category));
    }


    @DeleteMapping("{id}")
    public Result deleteCategory(@PathVariable Integer id){
        return Result.success(categoryService.deleteCategory(id));
    }

    @GetMapping
    public Result getList(@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum,
                          @RequestParam(name = "pageSize",defaultValue = "100") Integer pageSize){
        return Result.success(categoryService.getList(pageNum,pageSize));
    }


}
